package com.pbteach.shopping.service.impl;

import com.pbteach.shopping.dao.ProductDao;
import com.pbteach.shopping.entity.ProductDescript;
import com.pbteach.shopping.entity.ProductInfo;
import com.pbteach.shopping.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ProductServiceImpl
 * @Description: TODO
 * @Author wgc
 * @Date 2020/06/13 16:46
 * @Version V1.0
 **/
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDao productDao;


    @Override
    @Transactional
    public void createProduct(ProductInfo product) {
        for (int i = 1 ; i<20; i++){
            ProductDescript productDescript = new ProductDescript();
            productDescript.setDescript(product.getDescript());
            productDao.insertProductInfo(product);//新增商品基本信息
            productDescript.setProductInfoId(product.getProductInfoId());
            productDescript.setStoreInfoId(product.getStoreInfoId()); //冗余店铺信息
            productDao.insertProductDescript(productDescript);//新增商品描述信息
        }

    }

    @Override
    public List<ProductInfo> queryProduct(int page,int pageSize) {
        List<Map> maps = productDao.selectProductGroupList();
        int start = (page-1)*pageSize;
        List<ProductInfo> productInfos = productDao.selectProductList(start, pageSize);
        return productInfos;
    }

}
